/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.XmlDataBase;

import java.util.Collection;

/**
 *
 * @author Adam
 */
public class Movie {
    
    // TITLE == ID !!!, There can't be two movies with equals names in database
    
    private String title;
    private String length;
    private String note = null; // these elements are not compulsory
    private String format = null;
    private String genre = null;
    private Collection<String> languages;

    public Movie(String title, String length, String note, String format, String genre, Collection<String> languages) {
        this.title = title;
        this.length = length;
        this.note = note;
        this.format = format;
        this.genre = genre;
        this.languages = languages;
    }
    
    public Movie(){}
    
    public void setLanguages(Collection<String> languages){
        this.languages = languages;
    }
    public Collection<String> getLanguages() {
        return languages;
    }
    
    public void setLength(String length){
        this.length = length;
    }
    public String getLength() {
        return length;
    }

    public void setNote(String note){
        this.note = note;
    }
    public String getNote() {
        return note;
    }

    public void setTitle(String title){
        this.title = title;
    }
    public String getTitle() {
        return title;
    }
    
    public void setFormat(String format){
        this.format = format;
    }
    public String getFormat() {
        return format;
    }

    public void setGenre(String genre){
        this.genre = genre;
    }
    public String getGenre() {
        return genre;
    }    
       
    @Override
    public String toString(){
        StringBuilder result = new StringBuilder();
        result.append("Movie [");
        result.append("Title:" + getTitle() +", ");
        result.append("Length:" + getLength() +", ");
        if(this.genre != null)
            result.append("Genre:" + getGenre() +", ");
        if(this.format != null)
            result.append("Format:" + getFormat() +", ");
        if(this.note != null)
            result.append("Note:" + getNote() +", ");
        
        result.append("Languages: ");
        for(String lang : languages){
            result.append(lang + " ");
        }
        return result.toString();
    }
    
    @Override
      public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Movie other = (Movie) obj;
        if (this.title.equals(other.title) && this.length.equals(other.length) && this.languages.equals(other.languages) &&
           (this.genre == null || this.genre.equals(other.genre)) && (this.format == null || this.format.equals(other.format)) &&
           (this.note == null || this.note.equals(other.note)))
            return true;
        return false;
    }
    
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.title.hashCode() + this.length.hashCode() + this.languages.hashCode(); 
        hash +=  this.genre != null ? this.genre.hashCode() : 0;
        hash +=  this.format != null ? this.format.hashCode() : 0;
        hash +=  this.note != null ? this.note.hashCode() : 0;
        return hash;
    }
}
